<?
class HomeController extends BaseController{
    public function __construct($id = null){
        parent::__construct();
        $this->seo_string = '<title>Fone Care - Điện thoại giá rẻ, dịch vụ điện thoại</title>
                             <meta name="description" content="Fone Care, cung cấp điện thoại giá tôt, dịch vụ điện thoại uy tín chất lượng" />
                             <meta name="keywords" content="dtdd, dien thoai di dong, điện thoại di động, smartphone, dien thoai 2 sim 2 song, điện thoại 2 sim 2 song" />
                             <meta property="og:site_name" content="Fone Care - Điện thoại giá rẻ, dịch vụ điện thoại" />
	                         <meta property="og:image" content="http://fonecare.vn/template/default/themes/img/logo.png" />
                        	 <meta property="og:type" content="product" />
                        	 <meta property="og:url" content="http://fonecare.vn/" />
                        	 <meta property="og:title" content="Fone Care - Điện thoại giá rẻ, dịch vụ điện thoại" />
                        	 <meta property="fb:app_id" content="524593015322765" />
                        	 <meta property="fb:admins" content="100000472324543" />';
    }

    /*
     * Lấy ra sản phẩm mới show ra ngoài trang chủ
     */
    public function GetNewProduct(){
        $db_query = new db_query('SELECT pro_id, pro_name,pro_price,pro_hot,pro_new,
                                         pro_thumb, pro_promotion,fac_id,fac_name
                                  FROM products
                                  LEFT JOIN factory ON fac_id = pro_factory
                                  LEFT JOIN categories_multi ON cat_id = pro_cat_id
                                  WHERE pro_active = 1 AND cat_type != "service"
                                  ORDER BY pro_date DESC
                                  LIMIT 5');
        $list_pro = array();
        while($row = mysql_fetch_assoc($db_query->result)){
            $pro = array();
            $pro['link'] = generate_product_detail_url(array('pro_id'=>$row['pro_id'],'pro_name'=>$row['pro_name'],'fac_name'=>$row['fac_name']));
            $pro['thumb'] = PATH_PICTURE_PRODUCT . $row['pro_thumb'];
            $pro['hot'] = $row['pro_hot'];
            $pro['new'] = $row['pro_new'];
            $pro['price'] = $row['pro_price'];
            $pro['gift'] = $row['pro_promotion'];
            $pro['name'] = $row['pro_name'];
            $list_pro[] = $pro;
        }unset($db_query);
        //Lay ra hang san xuat
        $db_query = new db_query('SELECT fac_id,fac_name FROM factory');
        $list_factory = array();
        while($row = mysql_fetch_assoc($db_query->result)){
            $fac = array();
            $fac['link'] = generate_factory_url(array('fac_id'=>$row['fac_id'],'fac_name'=>$row['fac_name']));
            $fac['name'] = $row['fac_name'];
            $list_factory[] = $fac;
        }
        $html = HomeLayout::home_list_product(array('title'=>'Sản phẩm mới','pro'=>$list_pro,'factory'=>$list_factory));
        return $html;
    }
    /*
     * Sản phẩm có khuyến mại
     */
    public function GetPromotionProduct() {
        $db_query = new db_query('SELECT pro_id, pro_name,pro_price,pro_hot,pro_new,
                                         pro_thumb, pro_promotion,fac_name,fac_id
                                  FROM products
                                  LEFT JOIN factory ON fac_id = pro_factory
                                  LEFT JOIN categories_multi ON cat_id = pro_cat_id
                                  WHERE pro_active = 1 AND cat_type != "service" AND pro_promotion != "" AND pro_promotion IS NOT NULL
                                  ORDER BY pro_date DESC
                                  LIMIT 5');
        $list_pro = array();
        while($row = mysql_fetch_assoc($db_query->result)){
            $pro = array();
            $pro['link'] = generate_product_detail_url(array('pro_id'=>$row['pro_id'],'pro_name'=>$row['pro_name'],'fac_name'=>$row['fac_name']));
            $pro['thumb'] = PATH_PICTURE_PRODUCT . $row['pro_thumb'];
            $pro['hot'] = $row['pro_hot'];
            $pro['new'] = $row['pro_new'];
            $pro['price'] = $row['pro_price'];
            $pro['gift'] = $row['pro_promotion'];
            $pro['name'] = $row['pro_name'];
            $list_pro[] = $pro;
        }unset($db_query);
        //Lay ra hang san xuat
        $db_query = new db_query('SELECT fac_id,fac_name FROM factory');
        $list_factory = array();
        while($row = mysql_fetch_assoc($db_query->result)){
            $fac = array();
            $fac['link'] = generate_factory_url(array('fac_id'=>$row['fac_id'],'fac_name'=>$row['fac_name']));
            $fac['name'] = $row['fac_name'];
            $list_factory[] = $fac;
        }
        $html = HomeLayout::home_list_product(array('title'=>'Sản phẩm khuyến mại','pro'=>$list_pro,'factory'=>$list_factory));
        return $html;
    }
    
    /*
     * dịch vụ phần cứng
     */
    public function GetHardwaveService() {
        global $global_category_config;
        $db_query = new db_query('SELECT pro_id,pro_cat_id, pro_name,pro_price,
                                         pro_thumb, pro_promotion,
                                         cat_id,cat_type
                                  FROM products
                                  LEFT JOIN categories_multi ON cat_id = pro_cat_id
                                  WHERE pro_active = 1 AND cat_type = "service" AND(cat_id = '.$global_category_config['serviceHardID'].' OR cat_parent_id = '.$global_category_config['serviceHardID'].')
                                  ORDER BY pro_date DESC
                                  LIMIT 5');
        $list_pro = array();
        while($row = mysql_fetch_assoc($db_query->result)){
            $pro = array();
            $pro['link'] = generate_service_detail_url(array('pro_id'=>$row['pro_id'],'pro_name'=>$row['pro_name']));
            $pro['thumb'] = PATH_PICTURE_PRODUCT . $row['pro_thumb'];
            $pro['price'] = $row['pro_price'];
            $pro['name'] = $row['pro_name'];
            $list_pro[] = $pro;
        }unset($db_query);
        
        $html = HomeLayout::home_list_service(array('title'=>'Dịch vụ phần cứng','pro'=>$list_pro));
        return $html;
    }
    
    /*
     * dịch vụ phần mêm
     */
    public function GetSoftwaveService() {
        global $global_category_config;
        $db_query = new db_query('SELECT pro_id,pro_cat_id, pro_name,pro_price,
                                         pro_thumb, pro_promotion,
                                         cat_id,cat_type
                                  FROM products
                                  LEFT JOIN categories_multi ON cat_id = pro_cat_id
                                  WHERE pro_active = 1 AND cat_type = "service" AND(cat_id = '.$global_category_config['serviceSoftID'].' OR cat_parent_id = '.$global_category_config['serviceSoftID'].')
                                  ORDER BY pro_date DESC
                                  LIMIT 5');
        $list_pro = array();
        while($row = mysql_fetch_assoc($db_query->result)){
            $pro = array();
            $pro['link'] = generate_service_detail_url(array('pro_id'=>$row['pro_id'],'pro_name'=>$row['pro_name']));
            $pro['thumb'] = PATH_PICTURE_PRODUCT . $row['pro_thumb'];
            $pro['price'] = $row['pro_price'];
            $pro['name'] = $row['pro_name'];
            $list_pro[] = $pro;
        }unset($db_query);
        
        $html = HomeLayout::home_list_service(array('title'=>'Dịch vụ phần mềm','pro'=>$list_pro));
        return $html;
    }
    
    /*
     * linh phụ kiện
     */
    public function GetAccessories() {
        $db_query = new db_query('SELECT pro_id,pro_cat_id, pro_name,pro_price,
                                         pro_thumb, pro_promotion,fac_id,fac_name,
                                         cat_id,cat_type
                                  FROM products
                                  LEFT JOIN categories_multi ON cat_id = pro_cat_id
                                  LEFT JOIN factory ON fac_id = pro_factory
                                  WHERE pro_active = 1 AND cat_type = "combo"
                                  ORDER BY pro_date DESC
                                  LIMIT 5');
        $list_pro = array();
        while($row = mysql_fetch_assoc($db_query->result)){
            $pro = array();
            $pro['link'] = generate_product_detail_url(array('pro_id'=>$row['pro_id'],'pro_name'=>$row['pro_name'],'fac_name'=>$row['fac_name']));
            $pro['thumb'] = PATH_PICTURE_PRODUCT . $row['pro_thumb'];
            $pro['price'] = $row['pro_price'];
            $pro['name'] = $row['pro_name'];
            $list_pro[] = $pro;
        }unset($db_query);
        
        $html = HomeLayout::home_list_service(array('title'=>'Linh kiện','pro'=>$list_pro));
        return $html;
    }
}
?>